﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;

namespace ipdatacloud
{
    public class Scenes
    {
        public string Result { get; private set; }
        public string Scene { get; private set; }

        public Scenes(string result)
        {
            Result = result;
            ParseScene();
        }

        private void ParseScene()
        {
            string[] infos = Result.Split('|');
            if (infos.Length != 1)
            {
                throw new ArgumentException("查询结果格式错误或离线库非场景库");
            }
            Scene = infos[0] switch
            {
                "DYN" => "家庭宽带",
                "GOV" => "政府机构",
                "IDC" => "数据中心",
                "EDU" => "教育机构",
                "CDN" => "内容分发",
                "MOB" => "移动网络",
                "GTW" => "企业专线",
                "ORG" => "组织机构",
                "NET" => "基础设施",
                "BOGON" => "保留",
                "DNS" => "域名解析",
                _ => "-"
            };
        }
    }
    public class Location
    {
        public string Continent { get; private set; } // 洲
        public string Country { get; private set; } // 国家/地区
        public string Province { get; private set; } // 省份
        public string City { get; private set; } // 城市
        public string District { get; private set; } // 区县
        public string Isp { get; private set; } // 运营商
        public string AreaCode { get; private set; } // 区域代码
        public string CountryEnglish { get; private set; } // 国家/地区英文
        public string CountryCode { get; private set; } // 国家/地区英文简写
        public string Longitude { get; private set; } // 经度
        public string Latitude { get; private set; } // 纬度
        public string Elevation { get; private set; } // 海拔
        public string ZipCode { get; private set; } // 邮编
        public string CityCode { get; private set; } // 城市代码
        public string WeatherStation { get; private set; } // 气象站
        public string Asn { get; private set; }
        public string Preserve { get; private set; } // 预留
        public string Street { get; private set; } // 街道
        public string TimeZone { get; private set; } // 时区

        private string result;

        public Location(string result)
        {
            this.result = result;
            ParseLocation();
        }

        private void ParseLocation()
        {
            string[] infos = result.Split('|');
            if (infos.Length != 19)
            {
                throw new ArgumentException("查询结果格式错误或离线库非归属地库");
            }

            Continent = infos[0];
            Country = infos[1];
            Province = infos[2];
            City = infos[3];
            District = infos[4];
            Isp = infos[5];
            AreaCode = infos[6];
            CountryEnglish = infos[7];
            CountryCode = infos[8];
            Longitude = infos[9];
            Latitude = infos[10];
            Elevation = infos[11];
            ZipCode = infos[12];
            CityCode = infos[13];
            WeatherStation = infos[14];
            Asn = infos[15];
            Preserve = infos[16];
            Street = infos[17];
            TimeZone = infos[18];
        }

        public override string ToString()
        {
            return $"Location{{" +
                   $"continent='{Continent}', " +
                   $"country='{Country}', " +
                   $"province='{Province}', " +
                   $"city='{City}', " +
                   $"district='{District}', " +
                   $"isp='{Isp}', " +
                   $"areaCode='{AreaCode}', " +
                   $"countryEnglish='{CountryEnglish}', " +
                   $"countryCode='{CountryCode}', " +
                   $"longitude='{Longitude}', " +
                   $"latitude='{Latitude}', " +
                   $"elevation='{Elevation}', " +
                   $"zipCode='{ZipCode}', " +
                   $"cityCode='{CityCode}', " +
                   $"weatherStation='{WeatherStation}', " +
                   $"asn='{Asn}', " +
                   $"preserve='{Preserve}', " +
                   $"street='{Street}', " +
                   $"timeZone='{TimeZone}'" +
                   $"}}";
        }
    }

}


public class Proxy
{
    private readonly string result;
    private string isProxy;
    private string proxyType;
    private int proxyTime;

    public Proxy(string result)
    {
        this.result = result;
        this.proxyTime = 0;
        ParseProxy();


    }

    private void ParseProxy()
    {
        string[] infos = this.result.Split('|');
        if (infos.Length != 3)
        {
            throw new ArgumentException("查询结果格式错误或离线库非v2版代理库");
        }

        if (infos[0] == "否")
        {
            this.proxyType = ("不是代理");
        }
        else
        {
            this.isProxy = infos[0];
            this.proxyType = infos[1];
            this.proxyTime = int.Parse(infos[2]);
        }

    }

    public string ProxyType
    {
        get { return this.proxyType; }
    }
    public int ProxyTime
    {
        get { return this.proxyTime; }
    }
    public string  IsProxy
    {
        get { return this.isProxy; }
    }

}